nums = [0, 1, 2, 2, 3, 0, 4, 2], val = 2

var removeElement = function (nums, val) {
    let n = nums.length
    if (n === 0) {
        return n
    }
    let k = 0
    nums.forEach((item) => {
        if (item !== val) {
            nums[k] = item
            k++
        }
    })
    return k
}

console.log(removeElement(nums, val));
